<?php if((isset($_SESSION['sys_admin']))) {?>
<script>
function addRow( url ) {
	var tablenya = document.getElementById('table-form').tBodies[0];
	var count    = tablenya.rows.length;
	
	var a = eval("document.form.jmlrow").value;
	var a = parseInt(a) + 1;
	document.form.jmlrow.value = a;
	
	var newWindows = window.open('<?php echo site_url('master/dept/browsProd');?>', null, 'height=510, width=850, top=50, left=50, scrollbars=1, resizable=0, toolbar=0, location=0, directories=0, status=0, menubar=0');
	
	if(count>10) {
		tablenya.rows[1].cells[5].innerHTML = "<img src='"+url+"' title='Hapus' onclick='delRow(this.parentNode.parentNode)' style='cursor:pointer;' />";
	}
	
	var row = document.createElement('tr');
	row.setAttribute('rowIndex', count);
	
	var cell1 = document.createElement('td');
	cell1.innerHTML = "<input type='text' name='prod_id"+a+"' readonly='readonly' size='5' />";
	
	var cell2 = document.createElement('td');
	cell2.innerHTML = "<input type='text' name='product"+a+"' size='35' readonly='readonly' />";
	
	/*var cell3 = document.createElement('td');
	cell3.innerHTML = "<input type='text' name='jumlah"+a+"' size='5'  />";
	
	/*var cell4 = document.createElement('td');
	cell4.innerHTML = "<input type='text' name='merk"+a+"' size='10' readonly='readonly'  />";
	
	/*var cell5 = document.createElement('td');
	cell5.innerHTML = "<input type='text' name='total"+a+"' size='10' onKeyUp='hitung_quantity();'  />";*/
		
	var cell6 = document.createElement('td');
	cell6.innerHTML = "<input type='button' value='del' onclick='delRow(this.parentNode.parentNode)'  />";	

	row.appendChild(cell1);
	row.appendChild(cell2);	
	/*row.appendChild(cell3);
	/*row.appendChild(cell4);
	/*row.appendChild(cell5);*/
	row.appendChild(cell6);
	tablenya.appendChild(row);
}

function delRow( baris ){
	var tablenya = document.getElementById('table-form');
	var count    = tablenya.rows.length;
	tablenya.deleteRow( baris.rowIndex );
	if(count<=2) {
		tablenya.rows[1].cells[5].innerHTML = "";
	}
}

function delRow2( baris ){
	var tablenya = document.getElementById('table-form2');
	var count    = tablenya.rows.length;
	tablenya.deleteRow( baris.rowIndex );
	if(count<=3) {
		tablenya.rows[1].cells[7].innerHTML = "";
	}
}

function hitung_quantity(){
	//var r = eval("document.form.jmlrow2").value;
	//var r = parseInt(r) + 1;
	//document.form.jmlrow2.value = r;

	var i = eval("document.form.jmlrow").value;
	//var harsat = 0;
	//var total_harsat = 0;

	for(j=1;j<=i;j++){
		var stock_ 			= eval("document.form.stock"+j).value;
		var quantity_		= eval("document.form.quantity"+j).value;
		
		var selisih		 	= parseInt(stock_) - parseInt(quantity_);
		
		
	} 
	eval("document.form.stock"+i).value = selisih;
}
function hapus(){ 
	    if(addRow>2){ 
        var x=document.getElementById('table-form').deleteRow(addRow-1); 
        addRow--; 
	    } 
	}	
</script>
<div class="update-dept">
<div class="update-dept-atas"></div>
<div class="update-dept-tengah">
<?php 
	echo ! empty($h2_title) ? '<h2>' . $h2_title . '</h2>': '';
	echo ! empty($message) ? '<p class="message">' . $message . '</p>': '';

	$flashmessage = $this->session->flashdata('message');
	echo ! empty($flashmessage) ? '<p class="message">' . $flashmessage . '</p>': '';
?>
<?php
	if ( ! empty($link))
	{
		echo '<p id="bottom_link">';
		foreach($link as $links)
		{
			echo $links . ' ';
		}
		echo '</p>';
	}
?>

<form class="f-wrap-1" name="form"  method="post" action="<?php  ?>"  >
	<p>
		<label for="idberita">Dept ID:</label>
		<input type="text" class="form_field" name="dept_id" size="30" value="<?php echo set_value('dept_id', isset($default['dept_id']) ? $default['dept_id'] : ''); ?>" disabled="disabled" />&nbsp;(<i>Automatic</i>)
        <input type="hidden" class="form_field" name="dept_id" size="30" value="<?php echo set_value('dept_id', isset($default['dept_id']) ? $default['dept_id'] : ''); ?>" />
	</p>
	<?php echo form_error('dept_id', '<p class="field_error">', '</p>');?>
	
	<p>
		<label for="tanggal">Dept Name</label>
        <!--<select name="dept_name">
        <?php //foreach($show as $show) { ?>
        	<option value="<?php //echo $show->dept_name;?>" <?php if($dept_name = $show->dept_name) echo "selected";?>><?php echo $show->dept_name;?></option>
          <?php// } ?>
        </select>-->
		<input type="text" class="form_field" name="dept_name" size="30" value="<?php echo set_value('dept_name', isset($default['dept_name']) ? $default['dept_name'] : ''); ?>" />
		
	</p>
	<?php echo form_error('dept_name', '<p class="field_error">', '</p>');?>	
	
    <p>
    	<label>Product :</label> <input type="hidden" name="jmlrow" value="0">
            <table id="table-form" class="table1" cellpadding="0" cellspacing="0">
                <thead>
                    <tr>
                    <th>Pod Id</th>
                    <th>Prod Name</th>
                    <th>Action</th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
    </p>
    <p>
			<label>&nbsp; &nbsp;</label> <input type="button" value="Add" onClick="addRow()" class="tombol" />
	</p>
	<p>
		<label for="isi">Descr:</label>
		<textarea cols="50" rows="20" name="descr" class="tinymce"><?php echo set_value('descrx', isset($default['descrx']) ? $default['descrx'] : ''); ?></textarea>
		
	</p>
	<?php echo form_error('descr', '<p class="field_error">', '</p>');?>

			

	<p>
		<input type="submit" name="submit" id="submit" value=" Simpan " />
	</p>
</form>
</div>
<div class="update-dept-bawah"></div>
</div>
<?php } ?>